/**
 * Created by Administrator on 2017/5/28.
 */
$(function() {
    //header
    //移入 我的E宠 时显示下拉菜单
    $(".active1").mouseover(function () {
        $(".mypet").css("display", "block");
        $(".active1 img").css({"transform": "rotate(270deg)", "transition": "all .1s"});
    });
    $(".active1").mouseout(function () {
        $(".mypet").css("display", "none");
        $(".active1 img").css({"transform": "rotate(90deg)", "transition": "all .1s"});
    });
    $(".mypet").mouseover(function () {
        $(".mypet").css("display", "block");
        $(".active1 img").css({"transform": "rotate(270deg)", "transition": "all .1s"});
    });
    $(".mypet").mouseout(function () {
        $(".mypet").css("display", "none");
        $(".active1 img").css({"transform": "rotate(90deg)", "transition": "all .1s"});
    });
    //移入 收藏我 时显示下拉菜单
    $(".active2").mouseover(function () {
        $(".collect").css("display", "block");
        $(".active2 img").css({"transform": "rotate(270deg)", "transition": "all .1s"});
    });
    $(".active2").mouseout(function () {
        $(".collect").css("display", "none");
        $(".active2 img").css({"transform": "rotate(90deg)", "transition": "all .1s"});
    });
    $(".collect").mouseover(function () {
        $(".collect").css("display", "block");
        $(".active2 img").css({"transform": "rotate(270deg)", "transition": "all .1s"});
    });
    $(".collect").mouseout(function () {
        $(".collect").css("display", "none");
        $(".active2 img").css({"transform": "rotate(90deg)", "transition": "all .1s"});
    });
    //移入 商品分类 时箭头转动
    $(".active4").mouseover(function () {
        $(".active4 img").css({"transform": "rotate(180deg) translateX(-5px)", "transition": "all .1s"});
        $(".list10,.part").css("display", "block");
        $(".cat").css("display", "none");
    });
    $(".list10,.part").mouseover(function () {
        $(".list10,.part").css("display", "block");
    })
    $(".list10,.part").mouseout(function () {
        $(".list10,.part").css("display", "none");
    })
    $(".active4").mouseout(function () {
        $(".list10,.part").css("display", "none");
        $(".active4 img").css({"transform": "rotate(0) translateX(0)", "transition": "all .1s"});
    });


    $(".active3").mouseover(function () {
        $(".active3 img").css({"transform": "rotate(180deg)", "transition": "all .1s"});
        $(".list10,.part").css("display", "none");
        $(".cat").css("display", "block");
    });
    $(".cat").mouseover(function () {
        $(".cat").css("display", "block");
    })
    $(".cat").mouseout(function () {
        $(".cat").css("display", "none");
    })
    $(".active3").mouseout(function () {
        $(".cat").css("display", "none");
        $(".active3 img").css({"transform": "rotate(0)", "transition": "all .1s"});

    });
    //回顶部
    var a = document.getElementById("wrap_r_block7")
    a.onclick = function () {
        document.documentElement.scrollTop = 0;
        document.body.scrollTop = 0;
    }
    //送至
    $(".chongqing").mouseover(function(){
        $(".jiantou").css({"transtion":"all 1s","transform":"rotate(180deg)"});
        $(".dress_show").css("display","block");
    })
    $(".chongqing").mouseout(function(){
        $(".jiantou").css({"transtion":"all 1s","transform":"rotate(0deg)"});
        $(".dress_show").css("display","none");
    })
    $(".dress_show").mouseover(function(){
        $(".dress_show").css("display","block");
    })

    //商品增加减少
    var m=1;
    $('.product_wrap').on('click','.add',function(){
        var prize = $(this).parent().attr("data-prize");
        m ++;
        $(".present").val(m);
        var prizeStr = "￥" + (Number(prize)*m).toFixed(2);
        $('.totalPrize').html(prizeStr);
        $(".pay_count").html(m);
    }).on('click','.sub',function(){
        if(m>0){
            m --;
            $(".present").val(m);
        }
        var prize = $(this).parent().attr("data-prize");
        var prizeStr = "￥" + (Number(prize)*m).toFixed(2);
        $('.totalPrize').html(prizeStr);
        $(".pay_count").html(m);
    });
    //读取购物车数据
    if($.cookie('productData')){
        initCart();
    }
    function initCart(){
        var html = "",
            dataJson = JSON.parse($.cookie('productData'));
        for(var i = 0; i < dataJson.length; i++){
            html += '<div class="product">'+
                '<input type="checkbox" checked class="che">'+
                '<img style="width: 85px;height:85px;" src="'+dataJson[i].imgUrl+'" alt="">'+
                '<a href="javascript:;" class="nofly"><span>[不可空运]</span>'+dataJson[i].name+'</a>'+
                '<div class="youhuo">'+
                '<div class="tianjia" data-prize="'+ dataJson[i].prize +'">'+
                '<a href="javascript:;" class="sub">-</a><input class="present" value="'+dataJson[i].count+'"><a href="javascript:;" class="add">+</a>'+
                '</div>有货</div>'+
                '<b>￥'+dataJson[i].prize+'</b>'+
                '<a href="javascript:;" >[收藏]</a> <a href="javascript:;">[删除]</a>'+
                '</div>'
        }
        $('.product_wrap').append(html);
        console.log(dataJson);
    }

})